package com.lanou.fooddemo.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import com.lanou.fooddemo.R;
import com.lanou.fooddemo.adapter.NoticeInformationAdapter;
import com.lanou.fooddemo.dao.FoodDatabaseTool;
import com.lanou.fooddemo.util.CommonUtil;

import java.util.HashMap;
import java.util.List;

public class NoticeInformationActivity extends Activity {
    private final String LOG_TAG = "NoticeIActivity";

    /**
     * 声明数据库工具类
     */
    private FoodDatabaseTool databaseTool;
    /**
     * 声明列表
     */
    private ListView listView;
    /**
     * 声明列表适配器
     */
    private NoticeInformationAdapter adapter;
    private List<HashMap<String, String>> dataList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        //初始化视图
        initView();
        databaseTool.close();
    }

    /**
     * 视图初始化类
     */
    private void initView() {
        listView = (ListView) findViewById(R.id.noticeListView);

        //实例化数据工具类
        databaseTool = new FoodDatabaseTool(this);
        dataList = databaseTool.selectNoticeAll();
        if(CommonUtil.isListNotNull(dataList)) {
            Log.i(LOG_TAG, "notice list size = " + dataList.size());
        } else {
            Log.i(LOG_TAG, "notice list is null");
        }
        adapter = new NoticeInformationAdapter(this, dataList);
        listView.setAdapter(adapter);
    }
}
